#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;
const int MOD = 10000;

void matmul(int a[2][2], int b[2][2], int c[2][2]) {
  int res[2][2] = {0};
  rep(i, 0, 1) rep(j, 0, 1) rep(k, 0, 1) {
    res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
  }
  rep(i, 0, 1) rep(j, 0, 1) c[i][j] = res[i][j];
}
void matpow(int b[2][2], int p, int c[2][2]) {
  int res[2][2] = {{1, 0}, {0, 1}};
  while (p) {
    if (p & 1) matmul(res, b, res);
    matmul(b, b, b);
    p >>= 1;
  }
  rep(i, 0, 1) rep(j, 0, 1) c[i][j] = res[i][j];
}
int a[2][2] = {{1, 1}, {1, 0}}, b[2][2], c[2][2];
int n, m;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> n && n != -1) {
    if (n <= 1) {
      cout << n << endl;
      continue;
    }
    rep(i, 0, 1) rep(j, 0, 1) b[i][j] = a[i][j];
    matpow(b, n - 1, c);
    cout << c[0][0] << endl;
  }
  return 0;
}